import configApi, { ConfigType } from "@/api/config/config";

const unitOptions = ref<Array<{ label: string; value: string }>>([]);

// 导出初始化方法
export const initUnitConfig = async () => {
  try {
    const res = await configApi.getConfigListByType(ConfigType.Unit);
    unitOptions.value = res.map((item: any) => ({
      label: item.codeName,
      value: item.codeValue,
    }));
  } catch (err) {
    console.error("单位配置加载失败", err);
  }
};

const formatUnit = (unit: string) => {
  return unitOptions.value.find((item) => item.value === unit)?.label || "";
};

export { formatUnit };
